<template>
	<!-- 没有删除操作的评论列表展示 -->
	<view class="uniJudge" @click="toDetail">
		<view class="avatar flex alignCenter justConBetween">
			<view class="flex alignCenter">
				<view class="quesAva">
					<image :src="judgeItem.createUserAvatar ||'https://image.alhelp.net/uploads/20231104/4d491857ac50d21ebbcb25ff5bc254f8.png'" mode="widthFix"></image>
					<!-- <view class="focus">+</view> -->
				</view>
				<view class="">
					<view class="font14 bold">{{judgeItem.createUserName || '匿名评论者'}}</view>
					<view class="colorccc font12">{{judgeItem.createTime}}</view>
				</view>
			</view>
			<!-- <view class="colorccc font12">{{judgeItem.time}}</view> -->
			<uni-icons class="del" type="closeempty" color="#ccc" size="18" v-if="isMine" @click="delJudge"></uni-icons>
			<!-- <uni-icons v-if="isMine" color="#ccc" type="more-filled" size="22" @click="dotOperShow=true"></uni-icons> -->
		</view>
		<view class="judgeCon font14 color666">{{judgeItem.content}}</view>
		<!-- 三点操作 -->
		<uni-dotoper :dotOperShow="dotOperShow" :operList="operList" @cancelOper="dotOperShow=false" @chooseDotOper="chooseDotOper"></uni-dotoper>
	</view>
</template>

<script>
	import { delComment,delNoteCommend } from "@/api/send.js"
	export default {
		name:"uni-judge",
		props:{
			judgeItem:{
				type:Object,
				default(){
					return {}
				}
			}
		},
		data() {
			return {
				dotOperShow:false,
				operList:[{
					title:'删除',
					id:3
				}],
				isMine:false
			};
		},
		created() {
			this.isMine=(this.judgeItem.createUserId==uni.getStorageSync('userId')?true:false)
		},
		methods:{
			toDetail(){
				uni.navigateTo({
					url:''
				})
			},
			// 评论的更多操作
			judgeMore(){
				
			},
			delJudge(){
				uni.showModal({
					title: '提示',
					content: '确定删除该评论吗？',
					success:(res)=> {
						if (res.confirm) {
							if(this.judgeItem.notesId){
								// 删除笔记评论
								delNoteCommend({id:this.judgeItem.id}).then((res)=>{
									if(res.code==100000){
										uni.showToast({
											title:'删除成功',
											icon:'none'
										})
										this.dotOperShow=false
										this.$emit("delCommendSucc",this.judgeItem.id)
									}
								})
								return
							}else{
								delComment({id:this.judgeItem.id}).then((res)=>{
									if(res.code==100000){
										uni.showToast({
											title:'删除成功',
											icon:'none'
										})
										this.dotOperShow=false
										this.$emit("delCommendSucc",this.judgeItem.id)
									}
								})
							}
						} else if (res.cancel) {}
					}
				});
			},
			chooseDotOper(oper){
				console.log('oper',oper)
				uni.showModal({
					title: '提示',
					content: '确定删除该评论吗？',
					success:(res)=> {
						if (res.confirm) {
							if(this.judgeItem.notesId){
								// 删除笔记评论
								delNoteCommend({id:this.judgeItem.id}).then((res)=>{
									if(res.code==100000){
										uni.showToast({
											title:'删除成功',
											icon:'none'
										})
										this.dotOperShow=false
										this.$emit("delCommendSucc",this.judgeItem.id)
									}
								})
								return
							}else{
								delComment({id:this.judgeItem.id}).then((res)=>{
									if(res.code==100000){
										uni.showToast({
											title:'删除成功',
											icon:'none'
										})
										this.dotOperShow=false
										this.$emit("delCommendSucc",this.judgeItem.id)
									}
								})
								return
							}
							
						} else if (res.cancel) {}
					}
				});
				
			}
		}
	}
</script>

<style lang="scss" scoped>
@import "@/static/public.scss";
.uniJudge{
	border-bottom: 1px solid $bordercolor;
	padding: 30rpx 0;
}
.avatar{
	margin: 0 0 30rpx;
	.quesAva{
		width:76rpx;
		height:76rpx;
		flex-shrink: 0;
		margin-right: 20rpx;
		position: relative;
		image{
			border-radius: 50%;
			width:100%;
			height:100%;
		}
		.focus{
			position: absolute;
			bottom: -10rpx;
			left: 15%;
			width: 70%;
			background: $colorred;
			border-radius: 20rpx;
			height: 35rpx;
			line-height: 35rpx;
			text-align: center;
			color: #fff;
			z-index: 10;
		}
	}
}
</style>